package fr.univtoulouse2.m2ice;

import java.io.File;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Random;

import weka.classifiers.trees.J48;
import weka.clusterers.SimpleKMeans;
import weka.core.Attribute;
import weka.core.Instance;
import weka.core.Instances;
import weka.core.Utils;
import weka.core.converters.CSVLoader;

public class Main {

	public static void main(String[] args) throws Exception {
		CSVLoader CSV_cluster = new CSVLoader();
		try {
			MP3 mp3 = new MP3("ressources/wakawaka.mp3");
			// mp3.play();
			CSV_cluster.setFile(new File("Credit.csv"));
			Instances clusterData;
			clusterData = CSV_cluster.getDataSet();

			J48 beforeProcess = new J48();
			clusterData.setClassIndex(clusterData.numAttributes() - 1);
			beforeProcess.buildClassifier(clusterData);

			double correct = 0.0;
			double wrong = 0.0;
			for (int ni = 0; ni < clusterData.numInstances(); ni++) {
				if (beforeProcess.classifyInstance(clusterData.instance(ni)) == clusterData
						.instance(ni).classValue())
					correct++;
				else
					wrong++;
			}
			/*
			 * To measure the improvement in performance of the classifier we
			 * first measure the pre-processing performance.
			 */

			Instance xyz = new Instance(clusterData.numAttributes());


			System.out.println("Wrong " + wrong);
			System.out.println("Correct " + correct);
			System.out
					.println("The Classification Accuracy before processing: "
							+ (correct * 100.0 / (correct + wrong)) + "%");
			OneRun run = new OneRun();
			for (int test_index = 0; test_index < run.testSet.numInstances(); test_index++) {
				// Check if the predicted output matches the original class.
				if (run.FC.classifyInstance(run.testSet.instance(test_index)) == (run.testSet
						.instance(test_index)).classValue()) {//
					System.out.println(run.FC.classifyInstance(run.testSet
							.instance(test_index)));
					// results[test_index][iter]++;
				}
			}

			// mp3.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
}
